from common.base import Base, get_driver
from selenium.webdriver.common.by import By
import time

# 定义类
class RegisteredUserPage(Base):
    # 页面操作网址
    login_url = 'http://172.16.2.235:8080/ecshop/user.php?act=register'


    # 点击 注册用户
    def click_register_user(self):
        self.click((By.XPATH, '//a[@href="user.php?act=register"]'))

    def input_username(self, content):
        # 输入用户名
        self.send_keys((By.NAME, 'username'), content)

    def input_email(self, content):
        # 输入邮箱
        self.send_keys((By.NAME, 'email'), content)

    def input_password(self, content):
        # 输入密码
        self.send_keys((By.NAME, 'password'), content)

    def input_conform_password(self, content):
        # 再次输入密码确认
        self.send_keys((By.ID, 'conform_password'), content)

    def input_tel(self, content):
        # 输入电话
        self.send_keys((By.NAME, 'extend_field5'), content)

    def click_submit(self):
        # 点击 立即注册
        self.click((By.XPATH, "//input[@name='Submit']"))

if __name__ == '__main__':
    # 创建driver
    driver = get_driver()
    driver.get('http://172.16.2.235:8080/ecshop/user.php?act=register')
    # 创建页面对象
    register = RegisteredUserPage(driver)
    # 点击 注册用户
    register.click_register_user()
    # 输入用户名
    register.input_username('sss')
    time.sleep(1)
    # 输入邮箱
    register.input_email('123456@qq.com')
    time.sleep(1)
    # 输入密码
    register.input_password('abc123456')
    time.sleep(1)
    # 确认密码
    register.input_conform_password('abc123456')
    time.sleep(1)
    # 输入手机号
    register.input_tel('18799999999')
    time.sleep(1)

    # register.click_agreement()
    time.sleep(1)
    # register.click_submit()

    register.quit(2)
